<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="cache-control" content="no-cache">
    <title>流程中心</title>
    <!-- jQuery -->
    <script src="vendor/jquery/jquery.min.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        //钉钉、微信打开消息
        var url = "";
        loginform = "";
        getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name.toLocaleLowerCase() + "=([^&]*)(&|$)");
            var r = window.location.search.replace("__", "&").substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        };
 function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null){
            return decodeURI(r[2])
        }
        return null
        }
        $(function () { 
             debugger;		
            url = window.location.toString().replace("__", "&");
            var workflowCode = getQueryString("workflowCode");    
            var code = getQueryString("code");
			var InstanceId = getQueryString("InstanceId");
            var state = getQueryString("state");
			var workState = getQueryString("workState");
            var formId = getQueryString("formId");
            var date = getQueryString("date");                               
            var flag=true;
			var SheetCode=getQueryString("SheetCode");
            var WorkItemID=getQueryString("WorkItemID");
            var T=getQueryString("T");
            var Mode=getQueryString("Mode");
			var IsMobile=getQueryString("IsMobile");
			var openUrl="";
            $.ajax({
                url: "/Portal/InstanceController/validity",
                data: {
                    date: date
                },
                type: "POST",
                dataType: "JSON",
                async: false,
                success: function (data) {
                    if(data!=null && data!=undefined){
                        flag=data.data;
                    }
                }
            })	
            // 1为代办中心跳转 2.代办任务跳转 3.instance 流程链接  4.为待阅中心 5.移动端登录
			var flag2= getQueryString("flag");
			//放行流程跳转
			if(flag2==2||flag2==3||flag2==5){
			flag=true;
			}
            if(flag2==5||IsMobile){
			<!--openUrl="http://ec.tongji-ec.com.cn:8098/Portal/MobileRun.html?code="+code;-->
			<!--openUrl="http://bpm.tongji-ec.com.cn/Portal/MobileRun.html?code="+code;-->
			//openUrl="MobileRun.html?code="+code+"&workflowCode="+workflowCode+"&state="+state+"&workState="+workState+"&formId="+formId+"&date="+date+"&SheetCode="+SheetCode+"&WorkItemID="+WorkItemID+"&T="+T+"&Mode="+Mode+"&IsMobile="+IsMobile+"&flag="+flag2;
			openUrl="http://bpm.tongji-ec.com.cn/Portal/Mobile/index.html#/tab/home";
			window.location.href = openUrl;
			}			
            if(flag){

            }else {
                window.location.href = "http://ectest.tongji-ec.com.cn/index";
            }
			//debugger;

            $.ajax({
                url: "/Portal/Login/ValidateLogin",
                data: {
                    state: state,
                    code: code
                },
                async: false,
                success: function (data) {
				//debugger;
                     //Redirect();
                   flag=data.Success;
                }
            }) 	
            if(flag){    
               if(flag2==1){             
                  openUrl = "http://bpm.tongji-ec.com.cn/Portal/index.html#/app/Workflow/MyUnfinishedWorkItem";
               }else if(flag2==5){		
			     //openUrl="http://ec.tongji-ec.com.cn/Portal/Mobile/index.html#/tab/home";			
			   }else if(flag2==4){ 
                  openUrl = "http://bpm.tongji-ec.com.cn/Portal/index.html#/app/Workflow/MyUnReadWorkItem";	
               }else if(flag2==2){
			   debugger;
			      $.ajax({
                   url: "/Portal/InstanceController/workItem",
                   data: {
                    InstanceId: InstanceId,
                    code: code
                  },
                   async: false,
                   success: function (data) {
                     //Redirect();
                   var userState =data.data;
				   if(userState==0){
						Mode= "Work";
						openUrl ="http://bpm.tongji-ec.com.cn/Portal/formSheet.html?SheetCode="+SheetCode+"&Mode="+Mode+"&WorkItemID="+data.WorkItemID+"&T="+T+"&localLan=zh_CN";
				   }else if(userState==1){
						Mode= "View";
						openUrl ="http://bpm.tongji-ec.com.cn/Portal/formSheet.html?SheetCode="+SheetCode+"&Mode="+Mode+"&WorkItemID="+data.WorkItemID+"&T="+T+"&localLan=zh_CN";
				   }else{
					 openUrl = "http://bpm.tongji-ec.com.cn/Portal/InstanceSheets.html?InstanceId="+InstanceId;

				   }
                  }
                })

			    //openUrl ="http://bpm.tongji-ec.com.cn/Portal/formSheet.html?SheetCode="+SheetCode+"&Mode="+Mode+"&WorkItemID="+WorkItemID+"&T="+T+"&localLan=zh_CN";
			   }else if(flag2==3){                 
				    if(workState==1){
					openUrl = "http://bpm.tongji-ec.com.cn/Portal/InstanceSheets.html?InstanceId="+InstanceId;
					}else{
						
						$.ajax({
                              url: "/Portal/InstanceController/workItemId",
                              data: {
                                instanceId: InstanceId,
                                code: code
                                    },
                              async: false,
                              success: function (data) {
				              //debugger;
                              //Redirect();
                              var objectId =data.objectId;
							  var SheetCode =data.bizObjectSchemaCode;
				              if(objectId==null||objectId==""||objectId==undefined){
				               openUrl = "http://bpm.tongji-ec.com.cn/Portal/InstanceSheets.html?InstanceId="+InstanceId;
				              }else{
				              openUrl ="http://bpm.tongji-ec.com.cn/Portal/formSheet.html?SheetCode="+SheetCode+"&Mode=Work&WorkItemID="+objectId+"&localLan=zh_CN";
				               }
                             }
                         }) 																																																								
					}
				    
			   }else{		   
                    openUrl = "http://bpm.tongji-ec.com.cn/Portal/StartInstance.html?WorkflowCode="+workflowCode+"&formId="+formId;	
		         }         				  
           }else{       
             openUrl = "http://ectest.tongji-ec.com.cn/index";		
           }
             // alert(openUrl);		   
             window.location.href = openUrl;		   
        });
        // 重定向
        Redirect = function () {
            var formId = getQueryString("formId");
            var date = getQueryString("date");
			var flag= getQueryString("flag");
            var workflowCode = getQueryString("workflowCode");
			 if(flag==1){             
                  window.location.href = "http://bpm.tongji-ec.com.cn/Portal/index.html#/app/Workflow/MyUnfinishedWorkItem";
             }
             if(flag==2){             
                  window.location.href = "http://bpm.tongji-ec.com.cn/Portal/index.html#/app/Workflow/MyUnfinishedWorkItem";
             } 			 
            window.location.href = "http://bpm.tongji-ec.com.cn/Portal/StartInstance.html?WorkflowCode="+workflowCode+"&formId="+formId;
 }
        getUrlVars = function () {
            var vars = {};
            var hash;
            var hashs = window.location.href.replace("__", "&").slice(window.location.href.indexOf('?') + 1).split('&');
            for (var i = 0; i < hashs.length; i++) {
                hash = hashs[i].split('=');
                vars[hash[0]] = hash[1];
            }
            vars["IsMobile"] = "true";
            return vars;
        }
    </script>
</head>
<body>

</body>
</html>
